package org.lwj.web.controller;

import org.lwj.common.domain.ResponseResult;
import org.lwj.web.domain.User;
import org.lwj.web.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class UserController {

    @Resource
    private IUserService userService;

    @GetMapping("/select/{id}")
    public ResponseResult select(@PathVariable Long id) {
        User user = userService.getById(id);
        return new ResponseResult( user);
    }

    @PostMapping("/selectByXml")
    public ResponseResult selectByXml(@RequestBody User user) {
        user = userService.selectByXml(user);
        return new ResponseResult(user);
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody User user) {
        userService.updateById(user);
        user = userService.getById(user.getId());
        return new ResponseResult(user);
    }

    @GetMapping("/insert")
    public ResponseResult insert() {
        User user = new User();
//        user.setAge(18);
//        user.setName("张三");
//        user.setEmail("abc@123.com");
//
//        user.setAge(18);
//        user.setName("王五");
//        user.setEmail("bcd@234.com");

        user.setAge(18);
        user.setName("王五");
        user.setEmail("cde@345.com");
        userService.save(user);
        return new ResponseResult( user);
    }

}
